home *** CD-ROM | disk | FTP | other *** search
- Path: locutus.rchland.ibm.com!usenet
- From: pstaite@vnet.ibm.com
- Newsgroups: comp.lang.c++
- Subject: Re: overloading []
- Date: 16 Jan 1996 22:18:04 GMT
- Organization: IBM OS/2 Device Driver Development Rochester, MN
- Message-ID: <4dh86s$bfi@locutus.rchland.ibm.com>
- References: <4dgjbl$6i3@news1.goodnet.com>
- Reply-To: pstaite@vnet.ibm.com
- NNTP-Posting-Host: warpone.rchland.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4dgjbl$6i3@news1.goodnet.com>, geoff@goodguy (GEOFF CADIEN) writes:
-
- >my problem is this. Given,
- >foo *f;
- >f = new foo;
- >Now the only way I can use the subscript operator is to call it like
- this
- >f->operator[](1) = 10;
- >Is this the only way?
-
- No, you could do:
-
- (*f)[ 1 ] = 10;
-
- or what I would do:
-
- foo& f( *new foo );
- f[ 1 ] = 10;
-
- // later on:
-
- delete &f;
-
- Of course, you have to be careful of NULL comming back from new, or
- catching the exception if it is a newer new ;-)
-
-
- Phil Staite, team OS/2
- internet: pstaite@vnet.ibm.com internal: pstaite@rchland
-
-